import { ref, reactive, type Ref } from 'vue'
import { defineStore } from 'pinia'
import { store } from '.'

interface AppConfig {
  canEmbedIFramePage: boolean // 是否允许嵌入iframe页面
}

const _useAppStore = defineStore('app', () => {
  // ------------ 加载动画配置 ------------
  // state
  const pageLoading: Ref<boolean> = ref(true)
  // getter
  function getPageLoading(): boolean {
    return pageLoading.value
  }
  // action
  function setPageLoading(loading: boolean): void {
    pageLoading.value = loading
  }

  // ------------ app 级别项目配置 ------------
  // state
  const appConfig = reactive({} as AppConfig)

  return {
    pageLoading,
    getPageLoading,
    setPageLoading,
    appConfig
  }
})

export function useAppStore() {
  return _useAppStore(store)
}
